{layout name="layout/food" /}
<div class="row-content am-cf" id="appId">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">预付卡规则列表</div>
                </div>
                <div class="widget-body am-fr">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-sm">
                                    <a class="am-btn am-btn-primary am-radius"
                                       href="{:url('food.market.prepaid.card/add')}">
                                        <span class="am-icon-plus"></span> 新增
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-hover tpl-table-black">
                            <thead>
                            <tr>
                                <th>名称</th>
                                <th>门店</th>
                                <th>是否成组</th>
                                <th>一层规则(%)</th>
                                <th>二层规则(%)</th>
                                <th>三层规则(%)</th>
                                <th>四层规则(%)</th>
                                <th>五层规则(%)</th>
                                <th>创建时间</th>
                                <th>是否删除</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {if sizeof($list) > 0}
                            {foreach $list as $item}
                            <tr>
                                <td class="am-text-middle">{$item['name']}</td>
                                <td class="am-text-middle">{$item['shop_name']}</td>
                                <td class="am-text-middle">
                                    {if $item['is_group']==1}
                                    成组分配
                                    {else /}
                                    成交即分配
                                    {/if}
                                </td>
                                <td class="am-text-middle">{$item['one_level_value']}</td>
                                <td class="am-text-middle">{$item['two_level_value']}</td>
                                <td class="am-text-middle">{$item['three_level_value']}</td>
                                <td class="am-text-middle">{$item['four_level_value']}</td>
                                <td class="am-text-middle">{$item['five_level_value']}</td>
                                <td class="am-text-middle">{$item['create_time']}</td>
                                <td class="am-text-middle">
                                    {if $item['is_delete']==1}
                                    <span class="am-text-danger">删除</span>
                                    {else /}
                                    未删除
                                    {/if}
                                </td>
                                <td class="am-text-middle">
                                    <div class="tpl-table-black-operation">
                                        {if empty($item['spu_id']) && $item['is_delete']!=1}
                                        <a href="javascript:;" class="item-del tpl-table-black-operation-del"
                                           data-id="{$item['id']}">
                                            <i class="am-icon-trash"></i> 删除
                                        </a>
                                        <a href="javascript:;" @click="goods({$item['shop_id']})" class="tpl-table-black-operation-green">
                                            绑定商品sku
                                        </a>
                                        {/if}
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            {else /}
                            <tr>
                                <td colspan="7" class="am-text-center">暂无记录</td>
                            </tr>
                            {/if}
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">{:$list->render()}</div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：{:$list->total()}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="food/market/prepaid/tpl_goods" /}
<script src="/assets/plugins/vue/vue.min.js?v={$version}"></script>
<script src="/addons/food/js/select.data.js?v={$version}"></script>
<script>
    // 渲染页面
    new Vue({
        el: '#appId',
        data: {
            type: 10,
            checked: 10
        },
        methods: {
            goods(shopId) {
                $.selectData({
                    width: "1000px",
                    limitLen:1,
                    title: '选择商品',
                    uri: 'goods/skulist?shopId='+shopId,
                    dataIndex: 'goods_id',
                    done: function (data) {
                        if(data.length>1){
                            layer.msg('只能选择一个商品sku');
                            return
                        }
                        $.post("{:url('food.market.prepaid.card/bind')}", data[0], function (result) {
                            if(typeof(result) == 'string'){
                                result = JSON.parse(result);
                            }
                            result.code === 1 ? $.show_success(result.msg, result.url) : $.show_error(result.msg);
                        });
                    }
                });
            }
        }
    });
    $(function () {
        // 删除元素
        var url = "{:url('food.market.prepaid.card/delete')}";
        $('.item-del').del('id', url);
    });
</script>